package com.crm.dao.productionDAO;

import com.crm.pojo.Productioncategory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * 产品分类dao
 */
public interface ProductionCategoryDAO extends CrudRepository<Productioncategory,Long>, JpaSpecificationExecutor<Productioncategory> {
    //分页查询所有产品分类
    @Query("from Productioncategory p where p.productioncategoryIsDel='未删除'order by p.pcid desc")
    public List<Productioncategory> queryByPage(Pageable pageable);
    //模糊查询所有产品分类（通过pcid和pcname）
    @Query(nativeQuery = true,value = "select * from PRODUCTIONCATEGORY pc where (pc.PCID like ?1 or pc.PCNAME like ?1) and pc.PRODUCTIONCATEGORY_IS_DEL='未删除'")
    public List<Productioncategory> queryBypcidOrpcnameMh(String q);
    //模糊查询所有产品分类（通过pcid和pcname）但是不包含自己
    @Query(nativeQuery = true,value = "select * from PRODUCTIONCATEGORY pc where (pc.PCID like ?1 or pc.PCNAME like ?1) and pc.PRODUCTIONCATEGORY_IS_DEL='未删除'and pc.PCID!=?2")
    public List<Productioncategory> queryBypcidOrpcnameMh2(String q, String noteq);
    //根据父分类id查询分类
    public List<Productioncategory> findByPcpid(Long pcpid);
    //查询最大分类级数
    @Query(nativeQuery = true,value = "select max(pc.PCDEPTH) from PRODUCTIONCATEGORY pc where pc.PRODUCTIONCATEGORY_IS_DEL='未删除'")
    public int queryMaxDepth();


}
